//
// Created by LiuYou on 2021/11/29.
//

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>


class Sort {
public:
    /*
     * 一边写, 一边在脑子中想这个排序的过程。
     */
    static void selectionSort(std::vector<int>& arr) {
        if (arr.empty() || arr.size() == 1) {
            return;
        }

        for (int i = 0; i < arr.size() - 1; ++i) {
            int minIndex = i;
            for (int j = i + 1; j < arr.size(); ++j) {
                if (arr[minIndex] > arr[j]) {
                    minIndex = j;
                }
            }
            std::swap( arr[i], arr[minIndex] );
        }
    }
};


int main(int argc, char** argv) {
    std::vector<int> arr{3, 2, 5, 4, 1, 100, -1, 39, 33};
    std::vector<int> arr2( arr );

    {
        Sort::selectionSort( arr );
        std::copy( arr.begin(), arr.end(), std::ostream_iterator<int>( std::cout, " " ));
        std::cout << std::endl;
    }

    {
        std::sort( arr2.begin(), arr2.end());
        std::copy( arr2.begin(), arr2.end(), std::ostream_iterator<int>( std::cout, " " ));
        std::cout << std::endl;
    }


    return 0;
}
